package com.powernode.setting;

import com.powernode.interceptor.TokenInterceptor;
import com.powernode.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Autowired
    private TokenUtil tokenUtil;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*创建 token拦截器对象*/
        TokenInterceptor tokenInterceptor = new TokenInterceptor(tokenUtil,stringRedisTemplate);
        String [] inPath={
//                "/v1/user/info"
                "/v1/user/**"
        };
        String [] excludePath={
                "/v1/user/isRegister",
                "/v1/user/register",
                "/v1/user/accessToken"
        };
        registry.addInterceptor(tokenInterceptor)//添加拦截器
            .addPathPatterns(inPath)//拦截路径
            .excludePathPatterns(excludePath)//过滤不需要拦截的路径
        ;
//        registry.addInterceptor(其他拦截器)

    }
}
